﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;


namespace BLL
{
    public class Collect
    {
        //新增收藏夹，注意是收藏夹！创建一个用户的时候,为其生成一个收藏夹
        public int AddCollect(string account)
        {
            CollectInfo collect = new CollectInfo(account);
            DAL.Collect Collect = new DAL.Collect();
            return Collect.InsertCollect(collect);
        }

        //根据用户account删除其收藏夹,注销一个账户时，为其删除其收藏夹
        public int DelCollect(string account)
        {
            DAL.Collect Collect = new DAL.Collect();
            return Collect.DeleteCollect(account);
        }

        //根据用户account获取其收藏夹信息
        public CollectInfo GetCollect(string account)
        {
            DAL.Collect Collect = new DAL.Collect();
            return Collect.GetCollectInfo(account);
        }

        //添加收藏
        public int AddOneCollection(string account,string pid)
        {
            DAL.Collect Collect = new DAL.Collect();
            CollectInfo collect = new CollectInfo(account);           
            collect = Collect.GetCollectInfo(account);

            //collect.PidList = new List<string>();
            if (collect.PidList.Contains(pid))//如果收藏夹里有该pid
            {
                return 1;//重复收藏
            }
             else //如果收藏夹里没有该pid
            {
                //增加该id
                collect.PidList.Add(pid);
            }
            
            return Collect.UpdateCollect(collect, account);
        }
        //取消收藏
        public int DelOneCollection(string account,string pid)
        {
            DAL.Collect Collect = new DAL.Collect();
            CollectInfo collect = new CollectInfo();
            collect = Collect.GetCollectInfo(account);
            collect.PidList.Remove(pid);//移除List中的值为pid的一项
            return Collect.UpdateCollect(collect, account);
        }

        //更新Account
        public int UpdColAct(string newact, string oldact)
        {
            DAL.Collect Collect = new DAL.Collect();
            return Collect.UpdCollectionAct(newact, oldact);
        }
    }
}
